[TRTLLM-14551][perf] avoid GDN state reset host synchronization#16716
[TRTLLM-14551][perf] avoid GDN state reset host synchronization#16716liji-nv wants to merge 1 commit into
Conversation
|
/bot run --disable-fail-fast |
|
PR_Github #60933 [ run ] triggered by Bot. Commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThe GDN mixer adds a Triton helper to reset selected SSM and convolution cache states, replaces inline tensor assignments in ChangesGDN state reset
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant Qwen3NextGatedDeltaNet
participant _reset_gdn_states
participant _reset_gdn_states_kernel
participant StateBuffers
Qwen3NextGatedDeltaNet->>_reset_gdn_states: pass state buffers, indices, and initial-state flags
_reset_gdn_states->>_reset_gdn_states_kernel: launch masked reset
_reset_gdn_states_kernel->>StateBuffers: zero selected SSM and convolution slots
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
PR_Github #60933 [ run ] completed with state
|
f8026d7 to
57f5e21
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #61176 [ run ] triggered by Bot. Commit: |
|
PR_Github #61176 [ run ] completed with state
|
GDN prefill reset currently selects cache slots with a CUDA boolean mask before assigning zeros. The boolean-indexed selection has a data-dependent output shape, which forces the host to obtain the selected element count and introduces a stream synchronization for every GDN layer. Replace the two indexed assignments with a fixed-shape Triton launch. Each program reads the request's cache index and initialization flag on device, validates the cache slot, and clears both the SSM and convolution state rows in one kernel. Requests with initialized state or invalid sentinel indices remain untouched. Compute the state row offsets explicitly in int64. Recurrent-state views stride across the interleaved SSM and convolution pool, so multiplying an int32 cache index by either stride is not guaranteed to fit in int32 for a large pool. Add a CUDA unit test covering reset slots, preserved initialized slots, untouched unrelated slots, and the negative invalid-index sentinel. Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
57f5e21 to
2bd3f1e
Compare
|
/bot run --disable-fail-fast --add-multi-gpu-test |
|
PR_Github #61475 [ run ] triggered by Bot. Commit: |
|
PR_Github #61475 [ run ] completed with state
|
|
/bot run --disable-fail-fast --add-multi-gpu-test |
|
PR_Github #61562 [ run ] triggered by Bot. Commit: |
|
PR_Github #61562 [ run ] completed with state
|
GDN prefill reset currently selects cache slots with a CUDA boolean mask before assigning zeros. The boolean-indexed selection has a data-dependent output shape, which forces the host to obtain the selected element count and introduces a stream synchronization for every GDN layer.
Replace the two indexed assignments with a fixed-shape Triton launch. Each program reads the request's cache index and initialization flag on device, validates the cache slot, and clears both the SSM and convolution state rows in one kernel. Requests with initialized state or invalid sentinel indices remain untouched.
Add a CUDA unit test covering reset slots, preserved initialized slots, untouched unrelated slots, and the negative invalid-index sentinel.
Dev Engineer Review
_reset_gdn_states_kernel/_reset_gdn_states) intensorrt_llm/_torch/modules/mamba/gdn_mixer.pyto reset eligible GDN state rows (SSM and convolution) for a batch of requests by usingstate_indicesandhas_initial_statesdirectly on device.state_idxand computesneeds_reset = ~has_initial_states[request].state_idxvia0 <= state_idx < NUM_CACHE_LINES(treats-1as invalid).ssm_statesandconv_statesonly whenneeds_reset & valid_state, with additional boundsoffsets < SSM_STATE_SIZE/offsets < CONV_STATE_SIZE(row-size gating).forward_coreto replace the prior masked/host-influenced reset logic for prefills with a single call:_reset_gdn_states(ssm_states, conv_states, state_indices_p, has_initial_states_p)whennum_prefills > 0.grid = (num_requests, cdiv(max(state_sizes), 256))), index/sentinel handling, and ensuring the masked store prevents any out-of-bounds effects even whenstate_idxis invalid.QA Engineer Review
test_reset_gdn_states_preserves_initialized_and_invalid_slotsintests/unittest/_torch/modules/mamba/test_gdn_kernel_optimizations.py.state_poolbacking views forssm_states/conv_states._reset_gdn_stateswithstate_indices=[1, 3, -1]andhas_initial_states=[False, True, False].1is zeroed.3is preserved.-1does not modify any unrelated slot(s).tests/integration/test_lists/(test-db/qa) for this specific unit test could not be verified from search results.Description
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.